#!/bin/bash

echo "=== SSH 连接监控 ==="
echo "当前时间: $(date)"
echo

echo "活动用户连接:"
who

echo -e "\nSSH 进程统计:"
ps aux | grep sshd | grep -v grep | wc -l

echo -e "\n详细连接信息:"
netstat -tnpa | grep ':22' | awk '{print $5,$6,$7}' | sort | uniq -c

echo -e "\n最近的 SSH 登录尝试:"
sudo tail -n 5 /var/log/auth.log | grep sshd 